package com.vehicle_information_management_system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vehicle_information_management_system.pojo.DepartmentInfo;
import com.vehicle_information_management_system.service.DepartmentInfoService;
import com.vehicle_information_management_system.mapper.DepartmentInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author huawei
* @description 针对表【department_info】的数据库操作Service实现
* @createDate 2025-02-16 09:49:18
*/
@Service
public class DepartmentInfoServiceImpl extends ServiceImpl<DepartmentInfoMapper, DepartmentInfo>
    implements DepartmentInfoService{

    @Autowired
    private DepartmentInfoMapper departmentInfoMapper;
    @Override
    public IPage<DepartmentInfo> listPage(Integer pageNum, Integer pageSize, String search) {
        Page<DepartmentInfo> page = new Page<>(pageNum,pageSize);
        QueryWrapper<DepartmentInfo> queryWrapper = new QueryWrapper<>();
        if(StrUtil.isNotBlank(search)){
            queryWrapper.like("department_name",search);
        }
        return departmentInfoMapper.selectPage(page,queryWrapper);

    }

    @Override
    public void add(DepartmentInfo departmentInfo) {
        departmentInfoMapper.insert(departmentInfo);
    }

    @Override
    public void delete(Integer id) {
        departmentInfoMapper.deleteById(id);
    }

    @Override
    public void update(DepartmentInfo departmentInfo) {
        departmentInfoMapper.updateById(departmentInfo);
    }

    @Override
    public List<DepartmentInfo> getDepartmentInfo() {
        QueryWrapper<DepartmentInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("department_name","department_id");
        return departmentInfoMapper.selectList(queryWrapper);
    }
}




